/******************************************/
/******************************************/
/****  JS Document                     ****/
/****  by Andrew Mahon                 ****/
/****  amahon@gmail.com                ****/
/******************************************/
/******************************************/

(function(tc) {

	tc.fn.y5infinteScroll = function(options){
		var $y5is = this, _o = {}
		
		_o = tc.jQ.extend({
			
		},options)
		
		function _initialize(){
			tc.util.log("YeahYeahYeahYeahYeah InfiniteScroll Starting",'info')
			_setup_events()
			return $y5is
		}
		
		function _setup_events(){
			tc.jQ(document).bind('scroll',_documentScrollHandler)
			tc.events.bind('cellblockFramesLoaded',_cellblockFramesLoadedHandler)
		}
		
		function _documentScrollHandler(e){
			if(window.scrollY > document.height - 2500){
				tc.jQ(document).unbind('scroll',_documentScrollHandler)
				tc.events.trigger('fetchMoreFrames',{n_frames:10})
			}
		}
		
		function _cellblockFramesLoadedHandler(e,d){
			tc.jQ(document).unbind('scroll',_documentScrollHandler).bind('scroll',_documentScrollHandler)
		}
		
		return _initialize()
	}
})(tc);